define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/agency/index' + location.search,
                    add_url: 'user/agency/add',
                    edit_url: 'user/agency/edit',
                    // del_url: 'user/agency/del',
                    multi_url: 'user/agency/multi',
                    import_url: 'user/agency/import',
                    jiangli_url:'user/agency/jiangli',
                    table: 'agency',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'province', title: __('Province'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'area', title: __('Area'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'username', title: __('Username'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'id_number', title: __('Id_number'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'),searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.status},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'jrxz', title: __('今日新增'), operate: false},
                        {field: 'yiwancheng', title: __('已完成'), operate: false},
                        {field: 'daichuli', title: __('待处理'), operate: false},
                        {field: 'daishouhuo', title: __('待收货'), operate: false},
                        {field: 'daijiesuan', title: __('待结算'), operate: false},
                        {field: 'shibai', title: __('失败'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            // buttons: [
                            //     {
                            //         name: 'detail',
                            //         text: __('添加奖励'),
                            //         icon: 'fa fa-list',
                            //         classname: 'btn btn-xs btn-danger btn-magic btn-dialog',
                            //         url: 'user/agency/jiangli'
                            //     },
                            // ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        jiangli: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
